<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>微信公众号Markdown编辑器 - 主题自定义</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            transition: background-color 0.3s, color 0.3s;
        }
        
        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
            background-color: #f5f7fa;
            color: #333;
            line-height: 1.6;
            padding: 20px;
            max-width: 1400px;
            margin: 0 auto;
            min-height: 100vh;
        }
        
        body.dark-mode {
            background-color: #1a1d21;
            color: #e1e6ec;
        }
        
        /* 顶部导航栏 */
        .top-nav {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 25px;
            padding-bottom: 15px;
            border-bottom: 1px solid #e1e4e8;
        }
        
        .dark-mode .top-nav {
            border-bottom: 1px solid #4a5568;
        }
        
        .hamburger-menu {
            cursor: pointer;
            width: 42px;
            height: 42px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            gap: 5px;
            border-radius: 50%;
            background: #edf2f7;
            position: relative;
            z-index: 1001;
        }
        
        .dark-mode .hamburger-menu {
            background: #2d3748;
        }
        
        .menu-bar {
            width: 22px;
            height: 2px;
            background-color: #4a5568;
            border-radius: 1px;
            transition: all 0.3s ease;
        }
        
        .dark-mode .menu-bar {
            background-color: #cbd5e0;
        }
        
        .hamburger-menu.active .menu-bar:nth-child(1) {
            transform: translateY(7px) rotate(45deg);
        }
        
        .hamburger-menu.active .menu-bar:nth-child(2) {
            opacity: 0;
        }
        
        .hamburger-menu.active .menu-bar:nth-child(3) {
            transform: translateY(-7px) rotate(-45deg);
        }
        
        .sidebar {
            position: fixed;
            top: 0;
            left: -300px;
            width: 280px;
            height: 100vh;
            background: white;
            box-shadow: 5px 0 15px rgba(0,0,0,0.1);
            z-index: 1000;
            padding: 80px 20px 20px;
            transition: left 0.3s ease;
            overflow-y: auto;
        }
        
        .dark-mode .sidebar {
            background: #2d3748;
            box-shadow: 5px 0 15px rgba(0,0,0,0.3);
        }
        
        .sidebar.active {
            left: 0;
        }
        
        .sidebar h3 {
            margin: 25px 0 15px;
            padding-bottom: 10px;
            border-bottom: 1px solid #e2e8f0;
            color: #2c3e50;
        }
        
        .dark-mode .sidebar h3 {
            color: #e2e8f0;
            border-bottom: 1px solid #4a5568;
        }
        
        .theme-control {
            display: flex;
            flex-direction: column;
            gap: 20px;
        }
        
        .theme-control h4 {
            margin-bottom: 10px;
            color: #4a5568;
            font-size: 16px;
        }
        
        .dark-mode .theme-control h4 {
            color: #cbd5e0;
        }
        
        .theme-input {
            width: 100%;
            padding: 12px 15px;
            border-radius: 8px;
            border: 1px solid #e2e8f0;
            font-size: 14px;
            background: #f8fafc;
        }
        
        .dark-mode .theme-input {
            background: #1a202c;
            border-color: #4a5568;
            color: #e2e8f0;
        }
        
        .theme-textarea {
            width: 100%;
            height: 180px;
            padding: 15px;
            border-radius: 8px;
            border: 1px solid #e2e8f0;
            font-family: monospace;
            font-size: 14px;
            background: #f8fafc;
            resize: vertical;
        }
        
        .dark-mode .theme-textarea {
            background: #1a202c;
            border-color: #4a5568;
            color: #e2e8f0;
        }
        
        .theme-btn {
            padding: 12px 20px;
            border-radius: 8px;
            background: #3182ce;
            color: white;
            border: none;
            font-weight: 600;
            cursor: pointer;
            transition: background-color 0.2s;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
        }
        
        .theme-btn:hover {
            background: #2b6cb0;
        }
        
        .theme-btn.secondary {
            background: #e2e8f0;
            color: #4a5568;
        }
        
        .dark-mode .theme-btn.secondary {
            background: #4a5568;
            color: #e2e8f0;
        }
        
        .theme-btn.secondary:hover {
            background: #cbd5e0;
        }
        
        .dark-mode .theme-btn.secondary:hover {
            background: #718096;
        }
        
        .theme-buttons {
            display: flex;
            gap: 10px;
            margin-top: 10px;
        }
        
        .theme-buttons .theme-btn {
            flex: 1;
        }
        
        .theme-examples {
            margin-top: 20px;
            padding: 15px;
            background: #f8fafc;
            border-radius: 8px;
            border: 1px solid #e2e8f0;
        }
        
        .dark-mode .theme-examples {
            background: #1a202c;
            border-color: #4a5568;
        }
        
        .theme-examples h4 {
            margin-bottom: 10px;
            color: #4a5568;
            font-size: 15px;
        }
        
        .dark-mode .theme-examples h4 {
            color: #cbd5e0;
        }
        
        .theme-examples ul {
            padding-left: 20px;
            color: #718096;
            font-size: 14px;
            line-height: 1.6;
        }
        
        .dark-mode .theme-examples ul {
            color: #a0aec0;
        }
        
        .theme-examples li {
            margin-bottom: 5px;
        }
        
        /* 容器功能切换 */
        .container-switch {
            display: flex;
            background: #edf2f7;
            border-radius: 8px;
            padding: 5px;
        }
        
        .dark-mode .container-switch {
            background: #2c2f33;
        }
        
        .switch-tab {
            padding: 8px 20px;
            border-radius: 6px;
            cursor: pointer;
            font-size: 14px;
            font-weight: 600;
            color: #4a5568;
            transition: all 0.2s;
        }
        
        .dark-mode .switch-tab {
            color: #a0aec0;
        }
        
        .switch-tab.active {
            background: white;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
            color: #3182ce;
        }
        
        .dark-mode .switch-tab.active {
            background: #2d3748;
            color: #63b3ed;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
        }
        
        .theme-toggle {
            cursor: pointer;
            width: 42px;
            height: 42px;
            border-radius: 50%;
            background: #edf2f7;
            display: flex;
            justify-content: center;
            align-items: center;
            transition: background-color 0.3s;
        }
        
        .dark-mode .theme-toggle {
            background: #2d3748;
        }
        
        .theme-toggle:hover {
            background: #e2e8f0;
        }
        
        .dark-mode .theme-toggle:hover {
            background: #4a5568;
        }
        
        /* 编辑区域 */
        .editor-container {
            display: flex;
            gap: 25px;
            height: calc(100vh - 200px);
            min-height: 500px;
        }
        
        .editor-area, .preview-area {
            flex: 1;
            border-radius: 12px;
            background: white;
            overflow: hidden;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
            display: flex;
            flex-direction: column;
        }
        
        .dark-mode .editor-area, 
        .dark-mode .preview-area {
            background: #2d3748;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
        }
        
        .editor-header {
            padding: 15px 20px;
            font-size: 16px;
            font-weight: 600;
            background: #f7fafc;
            border-bottom: 1px solid #e2e8f0;
            color: #4a5568;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .dark-mode .editor-header {
            background: #4a5568;
            border-color: #2d3748;
            color: #e2e8f0;
        }
        
        .markdown-input {
            width: 100%;
            flex: 1;
            padding: 20px;
            font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace;
            font-size: 16px;
            line-height: 1.8;
            border: none;
            resize: none;
            background: white;
            color: #2d3748;
        }
        
        .dark-mode .markdown-input {
            background: #1a202c;
            color: #e2e8f0;
        }
        
        .markdown-input:focus {
            outline: none;
        }
        
        .markdown-input::placeholder {
            color: #a0aec0;
        }
        
        .preview-area {
            display: none;
            padding: 0;
        }
        
        .preview-content {
            flex: 1;
            padding: 30px;
            overflow-y: auto;
            font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
            background: white;
        }
        
        .dark-mode .preview-content {
            background: #1a202c;
            color: #e1e6ec;
        }
        
        /* 微信公众号默认样式 */
        .wechat-style h1 {
            font-size: 22px;
            font-weight: 700;
            margin: 30px 0 20px;
            padding-bottom: 10px;
            border-bottom: 1px solid #eee;
            text-align: center;
            color: #333;
        }
        
        .dark-mode .wechat-style h1 {
            color: #e1e6ec;
            border-bottom: 1px solid #4a5568;
        }
        
        .wechat-style h2 {
            font-size: 18px;
            font-weight: 600;
            margin: 25px 0 15px;
            padding-left: 10px;
            border-left: 4px solid #3498db;
            color: #2c3e50;
        }
        
        .dark-mode .wechat-style h2 {
            color: #a0c4ff;
            border-left: 4px solid #1abc9c;
        }
        
        .wechat-style h3 {
            font-size: 16px;
            font-weight: 600;
            margin: 20px 0 12px;
            color: #2c3e50;
        }
        
        .dark-mode .wechat-style h3 {
            color: #cbd5e0;
        }
        
        .wechat-style p {
            font-size: 15px;
            margin-bottom: 15px;
            line-height: 1.8;
            color: #333;
        }
        
        .dark-mode .wechat-style p {
            color: #e1e6ec;
        }
        
        .wechat-style a {
            color: #3498db;
            text-decoration: none;
            border-bottom: 1px solid rgba(52, 152, 219, 0.3);
            transition: all 0.2s;
        }
        
        .wechat-style a:hover {
            color: #2980b9;
            border-bottom: 1px solid #2980b9;
        }
        
        .wechat-style strong {
            color: #e74c3c;
        }
        
        .dark-mode .wechat-style strong {
            color: #ff9a9e;
        }
        
        .wechat-style em {
            color: #9b59b6;
        }
        
        .wechat-style ul, .wechat-style ol {
            padding-left: 25px;
            margin-bottom: 20px;
        }
        
        .wechat-style li {
            margin-bottom: 8px;
            color: #333;
        }
        
        .dark-mode .wechat-style li {
            color: #e1e6ec;
        }
        
        .wechat-style blockquote {
            border-left: 4px solid #3498db;
            background: #f8f9fa;
            padding: 12px 20px;
            margin: 20px 0;
            border-radius: 0 4px 4px 0;
            color: #555;
        }
        
        .dark-mode .wechat-style blockquote {
            background: #2d3748;
            border-left: 4px solid #1abc9c;
            color: #cbd5e0;
        }
        
        .wechat-style pre {
            background: #2d3748;
            border-radius: 6px;
            padding: 16px;
            margin: 20px 0;
            overflow: auto;
            font-size: 14px;
        }
        
        .dark-mode .wechat-style pre {
            background: #1e272e;
        }
        
        .wechat-style code {
            font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace;
            background: rgba(52, 152, 219, 0.1);
            padding: 2px 6px;
            border-radius: 4px;
            font-size: 90%;
            color: #e74c3c;
        }
        
        .dark-mode .wechat-style code {
            background: rgba(231, 76, 60, 0.15);
            color: #ff9a9e;
        }
        
        .wechat-style img {
            max-width: 100%;
            border-radius: 6px;
            display: block;
            margin: 20px auto;
            box-shadow: 0 3px 10px rgba(0,0,0,0.1);
        }
        
        .wechat-style table {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0;
        }
        
        .wechat-style th, .wechat-style td {
            border: 1px solid #ddd;
            padding: 10px;
            text-align: left;
        }
        
        .wechat-style th {
            background-color: #f8f9fa;
            font-weight: 600;
        }
        
        .dark-mode .wechat-style th {
            background-color: #2d3748;
        }
        
        /* 底部状态栏 */
        .status-bar {
            display: flex;
            justify-content: space-between;
            padding: 12px 20px;
            background: white;
            border: 1px solid #e2e8f0;
            border-radius: 8px;
            margin-top: 15px;
            font-size: 14px;
            color: #718096;
            box-shadow: 0 2px 5px rgba(0,0,0,0.05);
        }
        
        .dark-mode .status-bar {
            background: #2d3748;
            border-color: #4a5568;
            color: #a0aec0;
        }
        
        .char-count {
            font-weight: 600;
            color: #3498db;
        }
        
        .dark-mode .char-count {
            color: #1abc9c;
        }
        
        /* 响应式设计 */
        @media (max-width: 1024px) {
            .editor-container {
                flex-direction: column;
                height: auto;
            }
            
            .editor-area, .preview-area {
                min-height: 450px;
            }
        }
        
        @media (max-width: 768px) {
            .top-nav {
                flex-wrap: wrap;
                gap: 15px;
            }
            
            .container-switch {
                order: 3;
                width: 100%;
                justify-content: center;
            }
            
            .status-bar {
                flex-direction: column;
                gap: 10px;
                align-items: center;
            }
            
            .sidebar {
                width: 260px;
            }
        }
    </style>
</head>
<body>
    <!-- 顶部导航栏 -->
    <div class="top-nav">
        <!-- 汉堡菜单 -->
        <div class="hamburger-menu" id="hamburger-menu">
            <div class="menu-bar"></div>
            <div class="menu-bar"></div>
            <div class="menu-bar"></div>
        </div>
        
        <!-- 容器功能切换 -->
        <div class="container-switch">
            <div class="switch-tab active" id="edit-tab">编辑</div>
            <div class="switch-tab" id="preview-tab">预览</div>
        </div>
        
        <!-- 日夜模式切换 -->
        <div class="theme-toggle" id="theme-toggle">
            <i class="fas fa-sun"></i>
        </div>
    </div>
    
    <!-- 侧边栏菜单 - 主题管理 -->
    <div class="sidebar" id="sidebar">
        <h3><i class="fas fa-palette"></i> 主题管理</h3>
        
        <div class="theme-control">
            <div>
                <h4><i class="fas fa-link"></i> 导入外部主题</h4>
                <input type="text" class="theme-input" id="external-theme-url" placeholder="输入主题CSS文件链接">
                <button class="theme-btn" id="import-theme-btn">
                    <i class="fas fa-download"></i> 导入主题
                </button>
            </div>
            
            <div>
                <h4><i class="fas fa-code"></i> 自定义主题</h4>
                <textarea class="theme-textarea" id="custom-css" placeholder="在此处编写自定义CSS...">/* 在此编写自定义CSS样式 */
/* 例如: */
/*
.wechat-style h1 {
    color: #2c5282;
    border-bottom: 2px solid #cbd5e0;
    padding-bottom: 15px;
}

.wechat-style a {
    color: #2b6cb0;
    border-bottom: 1px dashed #90cdf4;
}
*/</textarea>
                <div class="theme-buttons">
                    <button class="theme-btn" id="apply-custom-css-btn">
                        <i class="fas fa-check"></i> 应用样式
                    </button>
                    <button class="theme-btn secondary" id="reset-custom-css-btn">
                        <i class="fas fa-undo"></i> 重置
                    </button>
                </div>
            </div>
            
            <div class="theme-examples">
                <h4><i class="fas fa-lightbulb"></i> 主题示例</h4>
                <ul>
                    <li>优雅主题：<code>https://example.com/elegant.css</code></li>
                    <li>科技主题：<code>https://example.com/tech.css</code></li>
                    <li>极简主题：<code>https://example.com/minimal.css</code></li>
                    <li>杂志主题：<code>https://example.com/magazine.css</code></li>
                </ul>
            </div>
        </div>
    </div>
    
    <!-- 编辑器/预览容器 -->
    <div class="editor-container">
        <!-- 编辑区域 -->
        <div class="editor-area">
            <div class="editor-header">
                <span><i class="fas fa-keyboard"></i> Markdown编辑区</span>
                <span>字数: <span id="edit-char-count">0</span></span>
            </div>
            <textarea class="markdown-input" id="markdown-input" placeholder="请输入Markdown文本...
            
示例：
# 文章标题
## 二级标题
### 三级标题

**加粗文本** 和 *斜体文本*

- 无序列表项1
- 无序列表项2
- 无序列表项3

1. 有序列表项1
2. 有序列表项2
3. 有序列表项3

> 这里是引用文本，通常用于强调重要内容

[链接描述](https://example.com)

![图片描述](https://free-for-dev.com/api/tools/image-placeholder?width=600&height=400&bg=ffffff&fg=333333&text=示例图片)

```javascript
// 代码块示例
function helloWorld() {
  console.log('Hello, World!');
}
```"></textarea>
        </div>
        
        <!-- 预览区域 -->
        <div class="preview-area" id="preview-area">
            <div class="editor-header">
                <span><i class="fas fa-eye"></i> 微信公众号预览</span>
                <span>字数: <span id="preview-char-count">0</span></span>
            </div>
            <div class="preview-content wechat-style" id="preview-content">
                <h1>预览模式</h1>
                <p>此处显示 Markdown 渲染结果</p>
            </div>
        </div>
    </div>
    
    <!-- 底部状态栏 -->
    <div class="status-bar">
        <div class="doc-status">状态: <span id="status">就绪</span></div>
        <div class="char-count">总字数: <span id="total-char-count">0</span></div>
    </div>
    
    <script>
        // DOM元素
        const markdownInput = document.getElementById('markdown-input');
        const previewContent = document.getElementById('preview-content');
        const themeToggle = document.getElementById('theme-toggle');
        const hamburgerMenu = document.getElementById('hamburger-menu');
        const sidebar = document.getElementById('sidebar');
        const editTab = document.getElementById('edit-tab');
        const previewTab = document.getElementById('preview-tab');
        const editCharCount = document.getElementById('edit-char-count');
        const previewCharCount = document.getElementById('preview-char-count');
        const totalCharCount = document.getElementById('total-char-count');
        const statusElement = document.getElementById('status');
        const previewArea = document.getElementById('preview-area');
        
        // 主题管理元素
        const externalThemeUrl = document.getElementById('external-theme-url');
        const importThemeBtn = document.getElementById('import-theme-btn');
        const customCss = document.getElementById('custom-css');
        const applyCustomCssBtn = document.getElementById('apply-custom-css-btn');
        const resetCustomCssBtn = document.getElementById('reset-custom-css-btn');
        
        // 当前应用的样式元素
        let importedThemeElement = null;
        let customStyleElement = null;
        
        // 初始内容
        const initialContent = `# 微信公众号排版指南

## 为什么选择Markdown?

Markdown是一种轻量级标记语言，它允许你使用易读易写的纯文本格式编写文档，然后转换成有效的HTML文档。

### 主要优点
- **简单易学**：语法简单，几分钟即可掌握
- **专注内容**：无需关注格式，专注于写作本身
- **平台通用**：可轻松转换为HTML、PDF等格式
- **高效排版**：快速实现微信公众号排版需求

## 基本语法示例

**加粗文本** 和 *斜体文本* 是常用的强调方式。

> 引用块常用于强调重要内容、名人名言或特别说明。引用块会以特殊样式呈现，吸引读者注意。

列表展示：

1. 有序列表项一
2. 有序列表项二
3. 有序列表项三

- 无序列表项一
- 无序列表项二
- 无序列表项三

## 链接与图片

访问[Markdown指南](https://www.markdownguide.org)了解更多语法。

![示例图片](https://free-for-dev.com/api/tools/image-placeholder?width=600&height=400&bg=ffffff&fg=333333&text=示例图片)

## 代码展示

\`\`\`javascript
// JavaScript代码示例
function calculateSum(a, b) {
  return a + b;
}

console.log(calculateSum(5, 10)); // 输出: 15
\`\`\`

## 表格示例

| 功能        | 语法           | 示例  |
|-------------|----------------|-------|
| 标题        | # 标题         | # H1 |
| 加粗        | **文本**       | **加粗文本** |
| 链接        | [文本](链接)   | [百度](https://baidu.com) |
| 图片        | ![描述](链接)  | ![图片](image.jpg) |

## 结语

使用Markdown可以大大提高微信公众号内容创作的效率，让你专注于内容本身而非排版。开始使用吧！`;

        // 设置初始内容
        markdownInput.value = initialContent;
        
        // 配置marked
        marked.setOptions({
            breaks: true,
            highlight: function(code, lang) {
                const language = hljs.getLanguage(lang) ? lang : 'plaintext';
                return hljs.highlight(code, { language }).value;
            }
        });
        
        // 更新预览
        function updatePreview() {
            const markdownText = markdownInput.value;
            previewContent.innerHTML = marked.parse(markdownText);
            
            // 更新字数统计
            const text = markdownText.replace(/\s/g, '');
            const charCount = text.length;
            editCharCount.textContent = charCount;
            previewCharCount.textContent = charCount;
            totalCharCount.textContent = charCount;
            
            // 更新状态
            statusElement.textContent = "已修改";
            statusElement.style.color = "#e74c3c";
            
            // 重新高亮代码块
            document.querySelectorAll('pre code').forEach((block) => {
                hljs.highlightBlock(block);
            });
        }
        
        // 初始化预览
        updatePreview();
        
        // 输入事件监听
        markdownInput.addEventListener('input', function() {
            updatePreview();
            
            // 如果当前在预览模式，确保切换到编辑模式
            if (previewArea.style.display === 'flex') {
                switchView('edit');
                editTab.classList.add('active');
                previewTab.classList.remove('active');
            }
        });
        
        // 主题切换
        let isDarkMode = false;
        themeToggle.addEventListener('click', function() {
            isDarkMode = !isDarkMode;
            document.body.classList.toggle('dark-mode', isDarkMode);
            const icon = this.querySelector('i');
            if (isDarkMode) {
                icon.classList.remove('fa-sun');
                icon.classList.add('fa-moon');
            } else {
                icon.classList.remove('fa-moon');
                icon.classList.add('fa-sun');
            }
        });
        
        // 汉堡菜单
        hamburgerMenu.addEventListener('click', function() {
            this.classList.toggle('active');
            sidebar.classList.toggle('active');
        });
        
        // 导入外部主题
        importThemeBtn.addEventListener('click', function() {
            const themeUrl = externalThemeUrl.value.trim();
            if (!themeUrl) {
                statusElement.textContent = "请输入有效的主题链接";
                statusElement.style.color = "#e74c3c";
                return;
            }
            
            // 移除之前导入的主题
            if (importedThemeElement) {
                importedThemeElement.remove();
            }
            
            // 创建新的link元素
            importedThemeElement = document.createElement('link');
            importedThemeElement.rel = 'stylesheet';
            importedThemeElement.href = themeUrl;
            document.head.appendChild(importedThemeElement);
            
            statusElement.textContent = `已导入外部主题: ${themeUrl}`;
            statusElement.style.color = "#3498db";
            
            // 清空输入框
            externalThemeUrl.value = '';
            
            setTimeout(() => {
                statusElement.textContent = "已修改";
                statusElement.style.color = "#e74c3c";
            }, 3000);
        });
        
        // 应用自定义CSS
        applyCustomCssBtn.addEventListener('click', function() {
            const cssCode = customCss.value.trim();
            if (!cssCode) {
                statusElement.textContent = "请输入自定义CSS代码";
                statusElement.style.color = "#e74c3c";
                return;
            }
            
            // 移除之前自定义的样式
            if (customStyleElement) {
                customStyleElement.remove();
            }
            
            // 创建新的style元素
            customStyleElement = document.createElement('style');
            customStyleElement.type = 'text/css';
            customStyleElement.textContent = cssCode;
            document.head.appendChild(customStyleElement);
            
            statusElement.textContent = "已应用自定义CSS";
            statusElement.style.color = "#3498db";
            
            setTimeout(() => {
                statusElement.textContent = "已修改";
                statusElement.style.color = "#e74c3c";
            }, 3000);
        });
        
        // 重置自定义CSS
        resetCustomCssBtn.addEventListener('click', function() {
            if (customStyleElement) {
                customStyleElement.remove();
                customStyleElement = null;
            }
            
            customCss.value = `/* 在此编写自定义CSS样式 */
/* 例如: */
/*
.wechat-style h1 {
    color: #2c5282;
    border-bottom: 2px solid #cbd5e0;
    padding-bottom: 15px;
}

.wechat-style a {
    color: #2b6cb0;
    border-bottom: 1px dashed #90cdf4;
}
*/`;
            
            statusElement.textContent = "已重置自定义CSS";
            statusElement.style.color = "#3498db";
            
            setTimeout(() => {
                statusElement.textContent = "就绪";
                statusElement.style.color = "";
            }, 3000);
        });
        
        // 编辑/预览切换
        function switchView(view) {
            if (view === 'edit') {
                editTab.classList.add('active');
                previewTab.classList.remove('active');
                document.querySelector('.editor-area').style.display = 'flex';
                previewArea.style.display = 'none';
            } else {
                editTab.classList.remove('active');
                previewTab.classList.add('active');
                document.querySelector('.editor-area').style.display = 'none';
                previewArea.style.display = 'flex';
                // 切换到预览时确保内容最新
                updatePreview();
            }
        }
        
        // 初始视图
        switchView('edit');
        
        // 视图切换事件
        editTab.addEventListener('click', () => switchView('edit'));
        previewTab.addEventListener('click', () => switchView('preview'));
    </script>
</body>
</html>